package net.zjitc.service.impl;

import net.zjitc.mapper.OrdersMapper;
import net.zjitc.mapper.ProductsMapper;
import net.zjitc.pojo.OrderItem;
import net.zjitc.pojo.Orders;
import net.zjitc.service.DownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author jinliwei
 * @Date 2019/4/14 23:10
 **/
@Service
@Transactional
public class DownloadServiceImpl implements DownloadService {
    @Autowired
    OrdersMapper ordersMapper;
    @Autowired
    ProductsMapper productMapper;
    @Override
    public List<OrderItem> downLoad(String year, String month){


        List<Orders> orderByYearAndMonth = ordersMapper.findOrdersByDate(year, month);
        List<OrderItem> orderByDateId = ordersMapper.findItemByOrdersid(orderByYearAndMonth);
        for (OrderItem o:orderByDateId) {
            o.setProducts(productMapper.findProductById(o.getProduct_id()));
        }
        return orderByDateId;
    }
}
